package com.huanxun.foodspath3;

import java.util.ArrayList;
import java.util.List;

import com.huanxun.application.MApplication;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 用户个人中心
 *
 */
public class UserActivity extends Activity implements OnClickListener {
	
	private Button bt_logout;
	private ImageView iv_back;
	private String loginname;
	private TextView tv_username;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acitvity_user);
		Intent intent = getIntent();
		loginname = intent.getStringExtra("loginname");
		initView();
	}

	private void initView() {
		iv_back = (ImageView) findViewById(R.id.iv_back);
		bt_logout = (Button) findViewById(R.id.bt_logout);
		tv_username = (TextView) findViewById(R.id.tv_username);
		tv_username.setText(loginname);
		bt_logout.setOnClickListener(new OnLayoutListener());
		iv_back.setOnClickListener(this);
	}
	
	private class OnLayoutListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			getSharedPreferences("config", Context.MODE_PRIVATE).edit().clear().commit();
			finish();
			MApplication application = (MApplication) getApplication();
			List<Activity> activities = application.activities;
			for (Activity activity : activities) {
				activity.finish();
			}
			Intent intent = new Intent(UserActivity.this, MainActivity.class);
			startActivity(intent);
		}
		
	}

	@Override
	public void onClick(View v) {
		finish();
	}
}
